package com.common.core.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by qujc on 15/6/4.
 */
public class RegExpTool {
    /**
     * 匹配手机号
     * @param input
     * @return
     */
    public static boolean matchPhoneNum(String input) {
        Pattern pattern = Pattern.compile("^[1]\\d{10}$");
        Matcher matcher = pattern.matcher(input);
        return matcher.matches();
    }


    /**
     * 匹配密码
     * @param input
     * @return
     */
    public static boolean matchPwd(String input) {
        Pattern pattern = Pattern.compile("^[0-9a-zA-Z]{6,20}$");
        Matcher matcher = pattern.matcher(input);
        return matcher.matches();
    }


    /**
     * 匹配验证码
     * @param input
     * @return
     */
    public static boolean matchVerifyCode(String input) {
        Pattern pattern = Pattern.compile("^\\d{4}$");
        Matcher matcher = pattern.matcher(input);
        return matcher.matches();
    }


    public static String findVerifyCode(String input) {

        Pattern pattern = Pattern.compile("第一视频");
        Matcher matcher = pattern.matcher(input);
        if (matcher.find()) {
            pattern = Pattern.compile("验证码");
            matcher = pattern.matcher(input);
            if (matcher.find()) {
                pattern = Pattern.compile("\\d{6}");
                matcher = pattern.matcher(input);
                if (matcher.find()) {
                    return matcher.group();
                }
            }
        }
        return "";
    }
}
